import request from '@/utils/request'

// 获取Spu列表的接口
const getSpuList = (page, limit, category3Id) => {
  return request({
    url: `admin/product/${page}/${limit}`,
    params: {
      category3Id
    }
  })
}

// 获取SPU信息
const getSpuById = (spuId) => {
  return request({
    url: `admin/product/getSpuById/${spuId}`
  })
}

// 获取品牌的信息
// GET /admin/product/baseTrademark/getTrademarkList
const getTrademarkList = () => {
  return request({
    url: `admin/product/baseTrademark/getTrademarkList`
  })
}

// 获取SPU图标接口的列表
const getSpuImageList = (spuId) => {
  return request({
    url: `admin/product/spuImageList/${spuId}`
  })
}

// /admin/product/baseSaleAttrList
// 获取平台的全部销售属性  整个平台一共3个
const getBaseSaleAttrList = () => {
  return request({
    url: `admin/product/baseSaleAttrList`
  })
}

// 修改或添加SPU的接口
const updateOrSaveSpuInfo = (spuInfo) => {
  if (spuInfo.id) {
    // 修改接口
    return request({
      url: '/admin/product/updateSpuInfo',
      method: 'post',
      data: spuInfo
    })
  } else {
    return request({
      url: '/admin/product/saveSpuInfo',
      method: 'post',
      data: spuInfo
    })
  }
}

// 删除SPU接口
const deleteSpu = (spuId)=>{
  return request({
    url:`/admin/product/deleteSpu/${spuId}`,
    method:'delete'
  })
}

export {
  getSpuList,
  getSpuById,
  getTrademarkList,
  getSpuImageList,
  getBaseSaleAttrList,
  updateOrSaveSpuInfo,
  deleteSpu
}
